package com.rdc.qingkou.presenter;


import android.widget.Toast;

import com.rdc.qingkou.Application.MyApplication;
import com.rdc.qingkou.base.BasePresenterImpl;
import com.rdc.qingkou.model.BrowseModel;
import com.rdc.qingkou.model.imodel.IBrowseModel;
import com.rdc.qingkou.presenter.ipresenter.IBrowsePresenter;
import com.rdc.qingkou.ui.iview.IBrowseView;
import com.rdc.qingkou.vo.CardAndUserVO;

import java.util.List;


public class BrowsePresenter extends BasePresenterImpl<IBrowseView> implements IBrowsePresenter {

    private IBrowseModel mBrowseModel;

    public BrowsePresenter() {
        mBrowseModel = new BrowseModel(this);
    }

    @Override
    public void getCardByKey(int userId, int currentPage, String url) {
        mBrowseModel.getCardByKey(userId, currentPage, url);
    }

    @Override
    public void getCardByTag(String tag, int currentPage) {
        mBrowseModel.getCardsByTag(tag, currentPage);
    }

    @Override
    public void getCardSuccess(List<CardAndUserVO> list) {
        if (isAttachView()) {
            getMvpView().updateCard(list);
        }
    }

    @Override
    public void getCardError(String message) {
        if (isAttachView()) {
            Toast.makeText(MyApplication.getContext(), message, Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void clearDisposable() {
        mBrowseModel.clearDisposable();
    }

    @Override
    public void subscribe(int subscribeId, int userId) {
        mBrowseModel.Subscribe(subscribeId, userId);
    }

    @Override
    public void subscribeError(String message) {
        if (isAttachView()) {
            Toast.makeText(MyApplication.getContext(), message, Toast.LENGTH_SHORT).show();
        }
    }


}
